using System;
using System.Collections.Generic;
using System.Text;

using Deepcode.Flux.Core.Extensions;

namespace Deepcode.Flux.Core.Services.MailHandlers
{
	/// <summary>
	/// Class representing a mail message that will be sent using the pluggable
	/// mail handler classes which allows us to swap out the mechanics of sending
	/// mail (eg for sending with SMTP-Auth etc)
	/// </summary>
	public class StandardMailMessage 
	{
		private string _From = "";
		private string _To = "";
		private string _CC = "";
		private string _Bcc = "";
		private string _Subject = "";
		private string _Body = "";
		private bool   _BodyIsHtml = false;

		public string From { get { return _From; } set { _From = value; } }
		public string To { get { return _To; } set { _To = value; } }
		public string CC { get { return _CC; } set { _CC = value; } }
		public string BCC { get { return _Bcc; } set { _Bcc = value; } }
		public string Subject { get { return _Subject; } set { _Subject = value; } }
		public string Body { get { return _Body; } set { _Body = value; } }
		public bool BodyIsHtml { get { return _BodyIsHtml; } set { _BodyIsHtml = value; } }

		/// <summary>
		/// Send using default mail server
		/// </summary>
		public void Send()
		{
			AddinTreeNode node = AddinTree.Tree.GetTreeNodeNoThrow("/Flux/Mail/");
			object o = node.BuildChildItem("handler", this);

			if( !(o is IMailHandler) ) throw new Exception("Error sending using current mail handler");
			IMailHandler mh = (IMailHandler) o;

			mh.SendMail( this );
		}
	}
}
